package com.lyluly.coursemgmt.webmodule.controller;

import com.lyluly.coursemgmt.servicemodule.iService.ILessonService;
import com.lyluly.coursemgmt.servicemodule.model.Lesson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @version v1.0
 * @author clc
 */
@Controller
@RequestMapping("/lessons")
public class LessonController {
    @Autowired
    private ILessonService iLessonService;

    /**
     * 添加一次课堂
     * @param lesson 课堂实体类
     * @param response
     */
    @PostMapping
    public void addLesson(@RequestBody Lesson lesson, HttpServletResponse response){
        iLessonService.addLesson(lesson);
    }

    /**
     * 根据课堂ID修改一次课堂
     * @param lesson 课堂实体类
     * @param response
     */
    @PutMapping
    public void modifyLesson(@RequestBody Lesson lesson, HttpServletResponse response){
        iLessonService.modifyLesson(lesson);
    }

    /**
     * 根据课堂ID删除一次课堂
     * @param lessonId 课堂ID
     * @param response
     */
    @DeleteMapping("/{lessonId}")
    public void removeLesson(@PathVariable int lessonId, HttpServletResponse response){
        iLessonService.removeLesson(lessonId);
    }

    /**
     * 根据课堂ID查找一次课堂
     * @param lessonId 课堂ID
     * @return 返回相应课堂
     */
    @GetMapping("/{lessonId}")
    @ResponseBody
    public Lesson findLessonById(@PathVariable int lessonId){
        return iLessonService.findLessonById(lessonId);
    }

    /**
     * 查找所有课堂
     * @return 返回所有课堂
     */
    @GetMapping
    @ResponseBody
    public List<Lesson> findLessonList(){
        return iLessonService.findLessonList();
    }
}
